﻿using System;
using System.IO;
using System.Runtime.Serialization;

namespace MyFloridaHouse.libSvUtilities
{
    public static class SerializationManager
    {
        public static byte[] Serialize(Object inst)
        {
            Type t = inst.GetType();
            DataContractSerializer dcs = new DataContractSerializer(t);
            MemoryStream ms = new MemoryStream();
            dcs.WriteObject(ms, inst);
            return ms.ToArray();
        }

        public static Object Deserialize(Type t, byte[] objectData)
        {
            DataContractSerializer dcs = new DataContractSerializer(t);
            MemoryStream ms = new MemoryStream(objectData);
            return dcs.ReadObject(ms);
        }
    }
}
